<!-- 
All rights Reserved, Designed By www.youyacao.com 
@Description:购买卡密
@author:成都市一颗优雅草科技有限公司     
@version 松鼠聚合直播系统v2.0
注意：本前端源码遵循 MulanPSL-2.0开源协议（木兰宽松许可证）本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584

 -->


<template>
    <div>
        <van-nav-bar
                title="购买卡密"
                left-text="返回"
                left-arrow
                fixed
                @click-left="onClickLeft"
        />
        <div style="padding-top: 46px;">
            <div style="padding: 10px; background: #eceef2; color: #7d7e80;">选择需要的卡密类型</div>
            <van-radio-group v-model="buycard">
                <van-cell-group>
                    <van-cell :title="card.title" clickable @click="buycard = card.name" v-for="card in cardlist">
                        <van-radio slot="right-icon" :name="card.name" />
                    </van-cell>
                </van-cell-group>
            </van-radio-group>
            <van-cell-group>
                <van-field v-model="cardcount" label="生成数量：" placeholder="单次生成不能超过100个" />
            </van-cell-group>
            <div style="padding: 30px 10px;"><van-button type="primary" size="large" style="height: 40px; line-height: 40px;" @click="doBuyCard()">确认生成卡密</van-button></div>
        </div>
    </div>
</template>

<script>
    import global_ from '../Global';
    import { Toast } from 'vant';
    import { Notify } from 'vant';
    export default {
        name: "buycard",
        data(){
            return {
                cardlist:[],
                buycard:"",
                cardcount:""
            }
        },
        created(){
            this.loadInfo();
        },
        methods:{
            onClickLeft:function () {
                this.$router.go(-1);
            },
            loadInfo:function () {
                this.$axios.get(global_.serverUrl+"admin/card/cardlist").then((res)=>{
                    if(res.code == 1){
                        this.cardlist = res.data;
                    }
                });
            },
            doBuyCard:function () {
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '提交中...'
                });
                this.$axios.post(global_.serverUrl+"admin/card/buy",{
                    buycard:this.buycard,
                    cardcount:this.cardcount
                }).then((res)=>{
                    toast.clear();
                    if(res.code != 1){
                        Toast(res.msg);
                    }else{
                        Notify({ type: 'success', message: '卡密生成成功' });
                        this.$router.replace("/");
                    }
                }).catch(()=>{
                    toast.clear();
                });
            }
        }
    }
</script>

<style scoped>

</style>
